package kr.co.onc.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import kr.co.onc.model.AdminModel;
import kr.co.onc.service.LoginService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Handles requests for the application home page.
 */
@Controller
public class LoginController {
	
	private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
	@Autowired
	private LoginService loginService;
	
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model,@RequestParam Map<String,Object> paramMap) {
		
		return "login";
	}
	
	@RequestMapping(value = "/LoginProc", method = RequestMethod.POST)
	public String LogInProc(HttpServletRequest request,Locale locale, Model model,@RequestParam Map<String,Object> paramMap) {
		
		
		AdminModel adminModel= loginService.getLogin(paramMap);
		
		if (adminModel==null) {
			model.addAttribute("message", "LOGIN_FAIL");
		}else{
			model.addAttribute("message", "LOGIN_SUCCESS");
			model.addAttribute("paramMap",paramMap);
			request.getSession().setAttribute("admin",adminModel);
		}
		
		return "common/result";
	}
	
	
	
	
	
	
}
